﻿<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>

    <!--JQuery UI-->
    <link rel="stylesheet" href="lib/jquery-ui.css" />
    <!--标签式输入框-->
    <link rel="stylesheet" href="lib/jquery.tagsinput.css" />
    <!--日期选择-->
    <link rel="stylesheet" href="lib/datepicker3.css" >
    <!--bootstrap-->
    <link rel="stylesheet" href="lib/bootstrap.min.css" >
    <!--font-awesome图标字体库-->
    <link rel="stylesheet" href="lib/font-awesome.css">
    <!--基础风格-->
    <link rel="stylesheet" href="lib/style.css" >
    <!--icheck-->
    <link rel="stylesheet" href="lib/custom.css" >
    <!--switchery-->
    <link rel="stylesheet" href="lib/switchery.css">
    <!--touchspin-->
    <link rel="stylesheet" href="lib/jquery.bootstrap-touchspin.min.css" >
    <!--Sweet Alert-->
    <link rel="stylesheet" href="lib/sweetalert.css" >

    <!--JQuery-->
    <script src="lib/jquery-2.1.1.js"></script>
    <!--JQuery UI-->
    <script src='lib/jquery-ui.custom.min.js'></script>
    <!--标签式输入框-->
    <script src="lib/jquery.tagsinput.js"></script>
    <!--switchery-->
    <script src="lib/switchery.js"></script>
    <!--icheck-->
    <script src="lib/icheck.min.js"></script>
    <!-- TouchSpin -->
    <script src="lib/jquery.bootstrap-touchspin.min.js"></script>
    <!--bootstrap-->
    <script src="lib/bootstrap.min.js"></script>
    <!-- Sweet alert -->
    <script src="lib/sweetalert.min.js"></script>
    <!-- Data picker -->
    <script src="lib/bootstrap-datepicker.js"></script>

    <!-- md5 -->
    <script src="libs/md5.js"></script>

    <!--websocket-->
    <!--<script src="lib/socket.io.js"></script>-->
    <script src="/socket.io/socket.io.js"></script>
    
    <!--服务器ip配置-->
    <script src="config.js"></script>
    <!--OEM-->
    <script src="oem.js"></script>
    <!-- 验证码 -->
    <script src="src/verify.js"></script>

    <!-- Toastr style -->
    <link href="lib/toastr.min.css" rel="stylesheet">
    <!-- Toastr script -->
    <script src="lib/toastr.min.js"></script>
    
    <script>
        //连接服务器
        sa_origins_host = window.location.protocol + "//" + window.location.host;
        var socket = io(sa_origins_host);
       
        //hook ajax open，捕捉错误
        var hook_ajax_open = XMLHttpRequest.prototype.open;
        XMLHttpRequest.prototype.open = function () {
            
            var xhrInstance = this; 
            xhrInstance.addEventListener("error", function (e) { 
                toastr.success('错误：无法连接到服务器!')
                //alert("Error while connecting to ShareWAF server!");
                return;
            });

            return hook_ajax_open.apply(this, arguments);        
        }
       
    </script>
    
</head>

<body>
    <div id="wrapper">
        <div class="ibox float-e-margins">

            <div class="ibox-title">
                <h5><i class="fa fa-shield"></i><span id="p_title"></span></h5>
                <div class="ibox-tools">

                    <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                        <i class="fa fa-question-circle"></i>
                    </a>
                    <ul class="dropdown-menu dropdown-user">
                        <li><a target="_blank" href="" id="oem_homepage_url"><span id="oem_homepage"></span></a></li>
                    </ul>
                </div>
                
            </div>

            <div class="ibox-content">
                <div class="panel-body">
                    <div class="tabs-container">

                        <!--Tab标题-->
                        <ul class="nav nav-tabs">
                            <li class="active"><a data-toggle="tab" href="#tab-1">登录</a></li>
                            <li class=""><a data-toggle="tab" href="#tab-2">管理中心</a></li>
                            <li class=""><a data-toggle="tab" href="#tab-3">状态监测</a></li>
                            <li class=""><a data-toggle="tab" href="#tab-4">其它</a></li>
                        </ul>

                        <!--Tab内容-->
                        <div class="tab-content">
                            <div id="tab-1" class="tab-pane active">
                                <div class="panel-body">
                                    
                                    <div class="row" id="div_login">
                                        <div class="col-sm-6 b-r">
                                        
                                            <h3 class="m-t-none m-b">管理员登录</h3>
                                            <div class="form-group"><label>帐号</label> <input id="login_username" type="text" placeholder="请输入管理员帐号" class="form-control"></div>
                                            <div class="form-group"><label>密码</label> <input id="login_password" type="password" placeholder="请输入管理员密码" class="form-control"></div>
                                            <label>验证码</label>
                                            <div id="verify_admin_login" style="width: 200px;height: 50px;"></div>
                                            <input type="text" id="code_admin_login_input" value="" placeholder="请输入验证码" class="form-control" style="width: 200px;"/><br>
                                            <div>
                                                <button class="btn btn-sm btn-primary pull-left m-t-n-xs" type="submit" onclick="verify_admin_login();"><strong>登录</strong></button>
                                                <script>

                                                    //验证码
                                                    var verifyCode_admin_login = new Verify_admin_login("verify_admin_login");
                                                    function verify_admin_login(){
                                                        var res = verifyCode_admin_login.validate(document.getElementById("code_admin_login_input").value);
                                                        if(res){
                                                            admin_login();
                                                        }else{
                                                            document.getElementById("code_admin_login_input").value = "";
                                                            document.getElementById("verifyCanvas2").click();
                                                            swal({
                                                                title: "",
                                                                text: "验证码错误。"
                                                            });	
                                                        }
                                                    }
                                                    /*
                                                    * 登录 开始
                                                    */
                                                    function admin_login(){
                                                        var username = document.getElementById("login_username").value;
                                                        var password = document.getElementById("login_password").value;
                                                        if (username.length == 0) {
                                                            swal({
                                                                title: "",
                                                                text: "帐号不能为空。"
                                                            });
                                                            //document.getElementById("login_username").focus();
                                                            return;
                                                        }
                                                        if (password.length == 0) {
                                                            swal({
                                                                title: "",
                                                                text: "密码不能为空。"
                                                            });
                                                            //document.getElementById("login_username").focus();
                                                            return;
                                                        }
                                                        
                                                        if(socket.connected == true){
                                                            //发送登录请求
                                                            socket.emit('admin_login',username,md5(password),document.getElementById("code_admin_login_input").value);
                                                        }else{
                                                            alert("错误：未连接到服务器！");
                                                        }
                                                        
                                                    }
                                                </script>
                                            </div>
                                            
                                        </div>
                                        <div class="col-sm-6">
                                            <a href="index.html">
                                            <button class="btn btn-sm btn-info m-t-n-xs"><strong>切换到用户中心</strong></button>
                                            </a>
                                        </div>
                                    </div>

                                    <div id="div_login_out" style="display: none">
                                        <button class="btn btn-sm btn-primary" onclick="exit();" ><i class="fa fa-refresh"></i> 退出登录</button>
                                        <script>
                                            function exit() {
                                                swal({
                                                    title: "提示！",
                                                    text: "已退出登录。"
                                                });
                                                document.getElementById("div_login").style.display="block";
                                                document.getElementById("div_login_out").style.display="none";

                                                document.getElementById("div_query").style.display="none";
                                                document.getElementById("div_query2").style.display="none";
	                                            document.getElementById("div_query_login_tip").style.display="block";
                                                document.getElementById("div_query_login_tip2").style.display="block";
                                                document.getElementById("div_tab_others").style.display="none";
                                                document.getElementById("div_tab_others_not_login").style.display="block";
                                            }
                                        </script>
                                        <a href="" data-toggle="modal" data-target="#myModal2" >
                                            <button class="btn btn-sm btn-info"><i class="fa fa-clock-o"></i> 修改密码</button>
                                        </a>
                                        <div class="modal inmodal" id="myModal2" tabindex="-2" role="dialog"  aria-hidden="true">
                                            <div class="modal-dialog">

                                                <div class="modal-content ">
                                                    <div class="modal-header">
                                                        <button id="close_icon" type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                                                        <i class="fa fa-clock-o modal-icon"></i>
                                                        <h4 class="modal-title">修改密码</h4>
                                                    </div>
                                                    <div class="ibox-content">
                                                        
                                                        <div class="row">
                                                            <div class="col-lg-8">
                                                                                                                                
                                                                <div class="form-group">
                                                                    <label>原始密码 *</label>
                                                                    <input id="old_password" type="password" class="form-control required">
                                                                </div>
                                                                <div class="form-group">
                                                                    <label>新密码 *</label>
                                                                    <input id="new_password" type="password" class="form-control required">
                                                                </div>
                                                                <div class="form-group">
                                                                    <label>再输一次新密码 *</label>
                                                                    <input id="new_password2" type="password" class="form-control required">
                                                                </div>
                                                                
                                                            </div>
                                                            <div class="col-lg-4">
                                                                <div class="text-center">
                                                                    <div style="margin-top: 20px">
                                                                        <i class="fa fa-sign-in" style="font-size: 180px;color: #e5e5e5 "></i>
                                                                    </div>
                                                                </div>
                                                            </div>
                                                        </div>
                    
                                                        <button type="button" class="btn btn-primary" onclick="change_password();"><i class="fa fa-user"></i> 确认修改</button>
                                                        <script>
                                                            function change_password(){
                                                                var old_password = document.getElementById("old_password").value;
                                                                var new_password = document.getElementById("new_password").value;
                                                                var new_password2 = document.getElementById("new_password2").value;
                                                                
                                                                if ( (old_password.length == 0) || (new_password.length == 0) || (new_password2.length == 0) ) {
                                                                    swal({
                                                                        title: "",
                                                                        text: "请认真输入。"
                                                                    });
                                                                    return;
                                                                }

                                                                if (new_password != new_password2) {
                                                                    swal({
                                                                        title: "",
                                                                        text: "两次输入的新密码不一致。"
                                                                    });
                                                                    return;
                                                                }

                                                                //发送密码修改请求
                                                                if(socket.connected == true){
                                                                    socket.emit('change_password', md5(old_password), md5(new_password));
                                                                }else{
                                                                    alert("未连接到服务器。请检查配置或向客服咨询。");
                                                                }
                                                                
                                                            }
                                                        </script>
                                                    </div>
                                                    
                                                    <div class="modal-footer">
                                                        <button type="button" class="btn btn-white" data-dismiss="modal" id="close_modal">关闭</button>
                                                    </div>
                                                </div>

                                            </div>
                                        </div>

                                    </div>
                                
                                    

                                </div>
                            </div>
                            
                            <div id="tab-2" class="tab-pane">
                                <div class="panel-body">
                                        
                                    <div id="div_query" style="display: none;">

                                        <div class="col-lg-12">
                                            <a href="" data-toggle="modal" data-target="#myModal1" >
                                                <button class="btn btn-sm btn-primary"><i class="fa fa-plus"></i> 新建</button>
                                            </a>
                                            <div class="modal inmodal" id="myModal1" tabindex="-1" role="dialog"  aria-hidden="true">
                                                <div class="modal-dialog">

                                                    <div class="modal-content ">
                                                        <div class="modal-header">
                                                            <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                                                            <i class="fa fa-clock-o modal-icon"></i>
                                                            <h4 class="modal-title">新建保护目标</h4>
                                                            <span class="badge badge-danger">重要提示</span>下面注册时，帐号填域名，不带http(s)://；保护目标填IP，带http(S)://。
                                                        </div>
                                                        <div class="ibox-content">
                                                            
                                                            <div class="row">
                                                                <div class="col-lg-8">
                                                                    <div class="form-group">
                                                                        <label>帐号 *</label>
                                                                        <input id="register_username" type="text" placeholder="请使用要保护的域名做为帐号，例：www.baidu.com" class="form-control required">
                                                                    </div>
                                                                    <div class="form-group">
                                                                        <label>保护目标 *</label>
                                                                        <input id="register_target" type="text" placeholder="被保护网站IP，可带端口，例：http://127.0.0.1:8080" class="form-control required">
                                                                    </div>
                                                                    <div class="form-group">
                                                                        <label>密码 *</label>
                                                                        <input id="register_password" type="password" class="form-control required">
                                                                    </div>
                                                                    <div class="form-group">
                                                                        <label>确认密码 *</label>
                                                                        <input id="register_confirm" type="password" class="form-control required">
                                                                    </div>
                                                                </div>
                                                                <div class="col-lg-4">
                                                                    <div class="text-center">
                                                                        <div style="margin-top: 20px">
                                                                            <i class="fa fa-sign-in" style="font-size: 180px;color: #e5e5e5 "></i>
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                            </div>
                        
                                                            <button type="button" class="btn btn-primary" onclick="register();"><i class="fa fa-user"></i> 确定</button>
                                                            <script>
                                                                function register(){
                                                                var register_username = document.getElementById("register_username").value;
                                                                var register_target = document.getElementById("register_target").value;
                                                                var register_password = document.getElementById("register_password").value;
                                                                var register_confirm = document.getElementById("register_confirm").value;

                                                                if (register_username.length == 0) {
                                                                    swal({
                                                                        title: "",
                                                                        text: "帐号不能为空。"
                                                                    });
                                                                    return;
                                                                }

                                                                if ((register_username.indexOf(".") == -1) || (register_username.length<5)){
                                                                    swal({
                                                                        title: "",
                                                                        text: "帐号有误，请检查。"
                                                                    });
                                                                    //document.getElementById("register_username").focus();
                                                                    return;
                                                                }

                                                                if (register_target.length == 0) {
                                                                    swal({
                                                                        title: "",
                                                                        text: "保护目标不能为空。"
                                                                    });
                                                                    return;
                                                                }


                                                                if ((register_target.indexOf(".") == -1) || (register_target.length<5)){
                                                                    swal({
                                                                        title: "",
                                                                        text: "保护目标有误，请检查。"
                                                                    });
                                                                    document.getElementById("register_target").focus();
                                                                    return;
                                                                }

                                                                if (register_target.toLowerCase().indexOf("http") == -1){
                                                                    swal({
                                                                        title: "",
                                                                        text: "保护目标需以http://或https://起始。"
                                                                    });
                                                                    document.getElementById("register_target").focus();
                                                                    return;
                                                                }

                                                                if (register_password.length == 0) {
                                                                    swal({
                                                                        title: "",
                                                                        text: "密码不能为空。"
                                                                    });
                                                                    return;
                                                                }

                                                                if (register_password.length <= 5) {
                                                                    swal({
                                                                        title: "",
                                                                        text: "密码太短了吧。"
                                                                    });
                                                                    return;
                                                                }

                                                                if (register_password != register_confirm) {
                                                                    swal({
                                                                        title: "",
                                                                        text: "两次输入的密码不一致。"
                                                                    });
                                                                    return;
                                                                }


                                                                //发送注册请求
                                                                socket.emit('register', register_username, register_password, register_target,"WangLiwen");
                                                            }
                                                            </script>
                                                                
                                                        </div>
                                                        
                                                        <div class="modal-footer">
                                                            <button type="button" class="btn btn-white" data-dismiss="modal" id="close_modal">关闭</button>
                                                        </div>
                                                    </div>

                                                </div>
                                            </div>
                                            <button class="btn btn-sm btn-primary" onclick="admin_get_webs();" ><i class="fa fa-refresh"></i> 刷新</button>
                                        </div>

                                        <div class="row show-grid" id="webs">
                                        </div>

                                    </div>
                                    
                                    <div id="div_query_login_tip">
                                        <span class="badge badge-danger">登录后才能使用</span>
                                    </div>
                                </div>
                            </div>
                            
                            <div id="tab-3" class="tab-pane">
                                <div class="panel-body">
                                    <div id="div_query2" style="display: none;">

                                        <button class="btn btn-sm btn-primary" onclick="admin_get_more_info()"><i class="fa fa-refresh"></i> 刷新</button>

                                        <div class="row">
                                            <div class="col-lg-4">
                                                <div class="panel panel-info">
                                                    <div class="panel-heading">
                                                        <i class="fa fa-info-circle"></i>系统信息-内存&CPU
                                                    </div>
                                                    <div class="panel-body" id="memory_cpu_info">
                                                        
                                                    </div>
            
                                                </div>
                                            </div>
                                            <div class="col-lg-4">
                                                <div class="panel panel-warning">
                                                    <div class="panel-heading">
                                                        <i class="fa fa-warning"></i> 系统信息-磁盘
                                                    </div>
                                                    <div class="panel-body" id="disk_info">
                                                        
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="col-lg-4">
                                                <div class="panel panel-danger">
                                                    <div class="panel-heading">
                                                         产品信息
                                                    </div>
                                                    <div class="panel-body" id="sharewaf_info">
                                                        
                                                    </div>
                                                    <div class="panel-footer">
                                                        <button class="btn btn-sm btn-primary" onclick="do_exit()"><i class="fa fa-refresh"></i> 关闭或重启</button>
                                                        <br>
                                                        如果是用forever或守护进程启动的话，服务会重启。
                                                    </div>
                                                </div>
                                            </div>
                                        </div>

                                    </div>
                                    
                                    <div id="div_query_login_tip2">
                                        <span class="badge badge-danger">登录后才能使用</span>
                                    </div>

                                </div>
                            </div>

                            <div id="tab-4" class="tab-pane">
                                <div class="panel-body">

                                    <div id="div_tab_others" style="display: none;">

                                        <button class="btn btn-sm btn-primary" onclick="window.open('download_sqlite3','_blank')">备份数据库</button>
                                        <button class="btn btn-sm btn-primary" onclick="window.open('download_log','_blank')">备份审计日志</button>

                                        <div class="row">
                                            <div class="col-lg-12">
                                                <div class="panel panel-info">
                                                    <div class="panel-heading">
                                                        <i class="fa fa-info-circle"></i> 审计日志
                                                    </div>
                                                    <div class="panel-body" >
                                                        <button class="btn btn-sm btn-primary" onclick="get_log();">刷新</button>
                                                        <br>
                                                        <div id="log_content" contenteditable="true" style="
                                                            display: block;
                                                            
                                                            height: 450px;
                                                            line-height: 20px;
                                                            padding: 10px;
                                                            margin: 0 auto;
                                                            border: 1px solid #ddd;
                                                            border-radius: 6px;
                                                            font-size: 12px;
                                                            word-wrap: break-word;
                                                            overflow-x: hidden;
                                                            overflow-y: auto;
                                                            -webkit-user-modify: read-write-plaintext-only;
                                                        ">
                                                        </div><br>
                                                        <input id="val" type="text"/>
                                                        <input type="button" value="高亮" onclick="search();"/>
                                                        <script>
                                                            function search(){
                                                                    var val = document.getElementById('val').value;
                                                                    var html = document.getElementById('log_content').innerHTML;
                                                         
                                                                    //清除上次搜索
                                                                    html = html.replaceAll('','');
                                                         
                                                                    if(val.length==0){
                                                                        document.getElementById('log_content').innerHTML = html;
                                                                        return false;
                                                                    }
                                                         
                                                                    var newHtml = html.replaceAll(val,'<span style="background:yellow">'+val+'</span>');
                                                         
                                                                    document.getElementById('log_content').innerHTML = newHtml;
                                                                    console.log(newHtml)
                                                                }
                                                         
                                                                //replaceAll替换函数
                                                                String.prototype.replaceAll = function(a,b){
                                                                    return this.replace(new RegExp(a,'gm'),b);
                                                                }
                                                        </script>
                                                    </div>
            
                                                </div>
                                            </div>
                                            
                                        </div>

                                    </div>
                                    
                                    <div id="div_tab_others_not_login">
                                        <span class="badge badge-danger">登录后才能使用</span>
                                    </div>

                                </div>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>

    <script>
        //按下回车时登录，按键信息对象以函数参数的形式传递进来了，就是那个e
        /*
        document.onkeyup = function (e) {
            //取出按键信息中的按键代码(大部分浏览器通过keyCode属性获取按键代码，但少部分浏览器使用的却是charCode)
            var code = e.charCode || e.keyCode;  
            if (code == 13) {
                verify_admin_login();
            }
        }
        */
    </script> 
   


    <script>
    admin_oem();
    function admin_oem(){
        document.title = oem_title;
        document.getElementById("p_title").innerHTML = oem_title;
        document.getElementById("oem_homepage").innerHTML = oem_name + "官网";
        document.getElementById("oem_homepage_url").href = oem_url;
    }
</script>

    <script>


         //管理员登录成功
        socket.on('admin_login_success',function(data){
            swal({
                title: "",
                text: "登录成功！"
            });

            document.getElementById("div_login").style.display="none";
            document.getElementById("div_login_out").style.display="block";

            document.getElementById("div_query").style.display="block";
            document.getElementById("div_query2").style.display="block";
	        document.getElementById("div_query_login_tip").style.display="none";
            document.getElementById("div_query_login_tip2").style.display="none";
            document.getElementById("div_tab_others").style.display="block";
            document.getElementById("div_tab_others_not_login").style.display="none";
            admin_get_webs();
            admin_get_more_info();
            setInterval(admin_get_more_info,5000);
            get_log();
            
        })

        //获取log信息
        function get_log(){
            socket.emit("get_log");
        }
        socket.on('get_log_success',function(data){
            document.getElementById("log_content").innerText = data.log;
        });
        socket.on('get_log_failed_too_large',function(data){
            document.getElementById("log_content").innerHTML = "日志文件已太大，不能获取。";
        });

        //获取保护目标
        function admin_get_webs(){
            //获取所有保护目标
            var username = document.getElementById("login_username").value;
            var password = document.getElementById("login_password").value;
            socket.emit('admin_get_webs',username,md5(password));
        }

        //获取系统信息等
        function admin_get_more_info(){
            var username = document.getElementById("login_username").value;
            var password = document.getElementById("login_password").value;
            socket.emit('admin_get_more_info',username,md5(password));
        }
        socket.on('get_disk_info_success',function(data){
            console.log("get_disk_info_success",data);
            document.getElementById("disk_info").innerHTML = data;
        });
        socket.on('get_memory_cpu_info_success',function(data){
            document.getElementById("memory_cpu_info").innerHTML = data;
        });
        socket.on('get_software_used_memory_success',function(data){
            document.getElementById("sharewaf_info").innerHTML = data;
        });

        //修改密码反馈
        socket.on('change_password_success',function(){

            swal({
                title: "",
                text: "修改密码成功"
            });
            //关闭注册窗口
	        document.getElementById("close_modal").click();
            exit();
        })
        socket.on('change_password_failed',function(data){

            swal({
                title: "修改密码失败",
                text: data
            });
        })

        //关闭或重启服务器
        function do_exit(){
            if(confirm("此操作将关闭或重启服务器，确定要这样操作吗？")){
                var username = document.getElementById("login_username").value;
                var password = document.getElementById("login_password").value;
                if(socket.connected == true){
                    socket.emit('do_exit',username,md5(password));
                }else{
                    alert("未连接到服务器！")
                }
            }
        }
        socket.on('do_exit_failed',function(data){
            swal({
                title: "",
                text: "操作失败，服务器未关闭或重启。"
            });
        })
        socket.on('do_exit_success',function(data){
            swal({
                title: "",
                text: "操作成功，服务器已关闭或重启。"
            });
        })

        //管理员登录失败
        socket.on('admin_login_failed',function(data){
            
            swal({
                title: "",
                text: "登录失败，帐号或密码错误！"
            });
            document.getElementById("code_admin_login_input").value = "";
            document.getElementById("verifyCanvas2").click();
        })

        socket.on('admin_login_vcode',function(data){
            
            swal({
                title: "",
                text: "验证码错误或已过期。"
            });
            document.getElementById("code_admin_login_input").value = "";
            document.getElementById("verifyCanvas2").click();
        })

         //管理员登录失败
         socket.on('admin_login_limit',function(data){
            
            swal({
                title: "",
                text: "登录受限中，请稍后再试！"
            });
            document.getElementById("code_admin_login_input").value = "";
            document.getElementById("verifyCanvas2").click();
        })

        //获取保护目标成功
        socket.on('admin_get_webs_success',function(data){
            
            document.getElementById("webs").innerHTML = "";

            var div;

            //标题
            {
                div = document.createElement("div");
                div.className = "col-md-1";
                div.innerHTML = "<b>NO.</b>"
                document.getElementById("webs").appendChild(div);

                div = document.createElement("div");
                div.className = "col-md-3";
                div.innerHTML = "<b>保护域名</b>"
                document.getElementById("webs").appendChild(div);

                div = document.createElement("div");
                div.className = "col-md-3";
                div.innerHTML = "<b>指向地址</b>"
                document.getElementById("webs").appendChild(div);

                div = document.createElement("div");
                div.className = "col-md-2";
                div.innerHTML = "<b>帐号</b>"
                document.getElementById("webs").appendChild(div);

                div = document.createElement("div");
                div.className = "col-md-2";
                div.innerHTML = "<b>密码</b>"
                document.getElementById("webs").appendChild(div);

                div = document.createElement("div");
                div.className = "col-md-1";
                div.innerHTML = "<b>管理</b>"
                document.getElementById("webs").appendChild(div);

            }           

            //内容
            for(i=0; i<data.shield_address.length; i++){
                div = document.createElement("div");
                div.className = "col-md-1";
                div.innerHTML = i + 1;
                //风格：内容超出后不换行
                div.style="white-space:nowrap;text-overflow:ellipsis;";
                document.getElementById("webs").appendChild(div);

                div = document.createElement("div");
                div.className = "col-md-3";
                div.innerHTML = data.shield_address[i][0];
                div.style="white-space:nowrap;text-overflow:ellipsis;";
                document.getElementById("webs").appendChild(div);

                div = document.createElement("div");
                div.className = "col-md-3";
                div.innerHTML = data.shield_address[i][1];
                div.style="white-space:nowrap;text-overflow:ellipsis;";
                document.getElementById("webs").appendChild(div);

                div = document.createElement("div");
                div.className = "col-md-2";
                div.innerHTML = data.shield_address[i][0];
                div.style="white-space:nowrap;text-overflow:ellipsis;";
                document.getElementById("webs").appendChild(div);

                div = document.createElement("div");
                div.className = "col-md-2";
                div.innerHTML = data.password[i];
                div.style="white-space:nowrap;text-overflow:ellipsis;";
                document.getElementById("webs").appendChild(div);

                div = document.createElement("div");
                div.className = "col-md-1";
                div.innerHTML = '<a class="label label-primary" onclick="admin_del_shield(\''+data.shield_address[i][0].trim()+'\');" >删除</a>';
                div.style="white-space:nowrap;text-overflow:ellipsis;";
                document.getElementById("webs").appendChild(div);
            }
        })

        //删除保护目标
        function admin_del_shield(domain){
            if( confirm("确定要删除吗？") == true){
                var username = document.getElementById("login_username").value;
                var password = document.getElementById("login_password").value;
                socket.emit('admin_del_shield',domain,username,md5(password));
            }
        }

        //获取保护目标失败
        socket.on('admin_get_webs_failed',function(data){
            swal({
                title: "",
                text: "获取保护目标失败。"
            });
        })

        //删除保护目标成功
        socket.on('admin_del_shield_success',function(data){
            swal({
                title: "",
                text: "删除成功。"
            });
            admin_get_webs();
        })
        //删除保护目标失败
        socket.on('admin_del_shield_failed',function(data){
            swal({
                title: "",
                text: "删除失败。"
            });
        })
        
        //注册失败，已达最大域名数量
        socket.on('register_faild_full',function(){
            swal({
                title: "添加失败",
                text: "服务器已达最大保护域名数量。"
            });	
        });

        //注册失败，域名已经存在
        socket.on('register_faild_exist',function(){
            swal({
                title: "添加失败",
                text: "域名已经存在。"
            });	
        });

        //注册成功
        socket.on('register_success',function(){
            swal({
                title: "",
                text: "添加成功。"
            });	
            //关闭注册窗口
            document.getElementById("close_icon").click();
            admin_get_webs();

        });

    </script>
</body>

</html>
